package com.atwisdom.star.dcs.Thread;

import cn.hutool.core.date.DateTime;
import com.atwisdom.star.dcs.service.Impl.RealTimeMonthStatServiceImpl;
import com.atwisdom.star.dcs.util.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class RealTimeInfoMonthTread implements Runnable  {


    @Autowired
    private RealTimeMonthStatServiceImpl realTimeMonthStatService;

    @Value("${das.monthHour}")
    private int monthHour;
    @Override
    public void run() {
        DateTime current = new DateTime();
        while (true) {
            if(current.hour(true) == monthHour){
                System.out.println("按月统计开始啦，我每天只跑一次，尽量不会影响你们工作");
                try {
                    realTimeMonthStatService.realTimeDataStat();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                System.out.println("今天的统计结束了，明天"+monthHour+"点重新开始");
                Utils.sleep(60000l * 60 * 2);
            }else{
                Utils.sleep(60000l * 10);
            }
            current = new DateTime();
        }
    }

}
